//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.utils.basehelper.bean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.BeanMap;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

public class BeanConvertUtils {
    public BeanConvertUtils() {
    }

    public static <T> T convert(Object source, Class<T> clazz) {
        if (source != null && clazz != null) {
            try {
                T target = clazz.newInstance();
                BeanUtils.copyProperties(source, target);
                return target;
            } catch (InstantiationException | IllegalAccessException var3) {
                throw new RuntimeException("对象转换异常");
            }
        } else {
            return null;
        }
    }

    public static <T> List<T> convertList(List<?> sources, Class<T> clazz) {
        if (!CollectionUtils.isEmpty(sources) && clazz != null) {
            List<T> targets = new ArrayList();
            sources.stream().forEach((source) -> {
                targets.add(convert(source, clazz));
            });
            return targets;
        } else {
            return new ArrayList();
        }
    }

    public static Map<?, ?> objectToMap(Object obj) {
        return obj == null ? null : new BeanMap(obj);
    }
}
